package com.hly.poitool.clazz;
import java.net.URL;
import java.net.URLClassLoader;
/**
 * @author : Jack Hao
 * @Date : 2022/3/30 17:49
 * @description :
 */
public class ModuleClassLoader extends URLClassLoader {

    private ModuleManager manager = new ModuleManager();

    public ModuleClassLoader(URL[] urls, ModuleManager manager) {
        super(urls);
        this.manager = manager;
    }

    /** * 重写了loadClass,优先从内存map查找要加载的类 */
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        if (manager.getCache().containsKey(name)) {
            return manager.getCache().get(name);
        } else {
            return super.loadClass(name, resolve);
        }
    }

}